﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using rgr;
using parser;
using System.Windows.Media;
using SQLVis.Entidades;


namespace SQLVis.Vizualizador
{
    public class SQLVisTreeMapNode : RGRTreeMapNode
    {
        public SQLVisTreeMapNode(SQLPattern myPattern)
            : base(myPattern.Count().ToString())
        {
            _Pattern = myPattern;
        }

        public SQLVisTreeMapNode(SQLPattern myPattern, long currentlevel)
            : base(myPattern.Count().ToString())
        {
            _Pattern = myPattern;
            _Level = currentlevel;
        }

        public SQLVisTreeMapNode(SQLPattern myPattern, Brush areaBrush, long currentlevel)
            : base(DisplayInfo(currentlevel,myPattern))
        {
            _Pattern = myPattern;
            //set the color of the node
            this.AreaBrush = areaBrush;
            _Level = currentlevel;
           
        }

        public long Level { get { return _Level; } set { _Level = value; } }

        public double AverageTime { get { return _Pattern.AverageTime; }  }

        public string PatternName { get { return _Pattern.PatternName; } }

        public override double Size { get { return _Pattern.Count() == 0 ? 1 : _Pattern.Count(); } }
        //TODO: think about the atributte mapping
        private SQLPattern _Pattern;

        private long _Level = 0;

        //internal decimal GetAvgTime()
        //{
        //    ;
        //}

        //dependiendo del nivel, mostramos diferente informacion
        //Nivel 0 = nada
        //Nivel 1 = el  cardinal de los hijos
        //Nivel 2 = el tiempo de cada query
        public static string DisplayInfo(long Mylevel, SQLPattern MyPattern)
        {
            string sResult = string.Empty;

            switch (Mylevel)
    	    {
                case 0:
                        sResult = "A";
                        break;
                case 1:
                        sResult = MyPattern.Count().ToString();
                        break;
                case 2:
                        sResult = MyPattern.AverageTime.ToString() + "Seg";
                        break;
		        default:
                        sResult = "Error";
                        break;
	        }
        
            return sResult;
        }

        public override string ToString()
        {
            return this._Pattern.ToString();
        }



    }

    
}
